jsx3.Class.defineClass(
        "tibco.admin.monitormanage.uicomponents.table.containers.Containers", //the full name of the class to create
        jsx3.gui.Block, //  extends
        null, // implements
        function (plugin) {
        	plugin.tableCacheId = "SPM_CONTAINERS_TABLE_CACHE";
        	
        	plugin.wsEndpointURL = tibco.admin.monitormanage.framework.mainPage.MainPage.wsEndpointURL;
        	
        	plugin.prototype.containerIds;

            plugin.prototype.init = function() {
                this.jsxsuper();
            }
            
            plugin.prototype.getNamespace = function() {
				return "tibco.admin";
			}
            
            plugin.prototype.setUpComponent = function() {
            	var subject = tibco.admin.monitormanage.uicomponents.page.gridInfrastructure.GridInfrastructure.nodeInfoCacheSubject;
            	tibco.admin.monitormanage.general.PageBusUtils.subscribe(subject, this.handleDisplayScreen, this);
            }
            
            plugin.prototype.handleDisplayScreen = function(subject, message, tableObj) {
            	tableObj.loadContent(tableObj);
            }
            
            plugin.prototype.loadContent = function(tableObj) {
           		var nodeInfoDoc = tibco.admin.Main.getServer().Cache.getDocument(tibco.admin.monitormanage.uicomponents.page.gridInfrastructure.GridInfrastructure.nodeScreenCacheId);
       		 	if(nodeInfoDoc)
       		 	{
          			tableObj.containerIds = new jsx3.util.List();
           			var nodeInfoRecord = nodeInfoDoc.getFirstChild();
           			var childRecords = nodeInfoRecord.getChildNodes();
           			for(i = 0; i < childRecords.size(); i++)
           			{
           				var childRecord = childRecords.get(i);
           				if(childRecord.getAttribute("recordName") == "container")
           				{
           					var containerId = childRecord.getAttribute("containerKey");
           					tableObj.containerIds.add(containerId);
           				}
           			}
            			
           			tableObj.callGetContainers(tableObj, tableObj.containerIds);
            	}
            }
            
            //call this method to begin the service call (eg.service.callgetContainers();)
    		plugin.prototype.callGetContainers = function(tableObj, containerIds) {
    			var dataPath = "tibco/admin/monitormanage/uicomponents/table/containers/data/containersData.xml";
    			var rulesPath = "tibco/admin/monitormanage/uicomponents/table/containers/rules/containersRules.xml";
    			if(tibco.admin.Main.getServer().getEnv("MODE")) 
    			{
					// mode is live
					var objService = tibco.admin.Main.loadService(tableObj.getNamespace(), rulesPath, "getContainers");
					objService.setEndpointURL(plugin.wsEndpointURL);
					// this setInboundURL should not be required...only here because of a current AMX framework bug
					objService.setInboundURL(dataPath);
				}
				else 
				{
					var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(tableObj.getNamespace(), rulesPath), "getContainers", null, null);
					// mode is static
					objService.setInboundURL(tibco.admin.Main.resolveURI(tableObj.getNamespace(), dataPath));
				}
				
				objService.containerObj = this;
				objService.containerIds = containerIds;
				
				// initialize the list of metrics we wish to retrieve data for
				var metricsList = new jsx3.util.List();
				metricsList.add("type");
				metricsList.add("version");
				objService.metricsList = metricsList;

      			//subscribe and call
      			objService.subscribe(jsx3.net.Service.ON_SUCCESS, tableObj.ongetContainersSuccess);
      			objService.subscribe(jsx3.net.Service.ON_ERROR, tableObj.ongetContainersError);
      			objService.subscribe(jsx3.net.Service.ON_INVALID, tableObj.ongetContainersInvalid);
      			objService.doCall();
    		};

    		plugin.prototype.ongetContainersSuccess = function(objEvent) {
     			//var responseXML = objEvent.target.getInboundDocument();
      			//jsx3.log("Success","The service call was successful.");
      			
      			// repaint the table
             	objEvent.target.containerObj.getDescendantOfName("containersTable_MM_Infra").repaintData();
    		};

    		plugin.prototype.ongetContainersError = function(objEvent) {
      			var myStatus = objEvent.target.getRequest().getStatus();
      			jsx3.log("Error","The service call failed. The HTTP Status code is: " + myStatus);
    		};

    		plugin.prototype.ongetContainersInvalid = function(objEvent) {
      			jsx3.log("Invalid","The following message node just failed validation:\n\n" + objEvent.message);
    		};
            

        });